package org.pentaho.actioneditor.client.actionpanels;

import com.google.gwt.user.client.ui.*;
import org.pentaho.actioneditor.client.messages.Messages;
import com.google.gwt.user.client.Command;


public class JFreeReportActionUI {

  private FlexTable root = new FlexTable();
  private TextBox name = new TextBox();
  private TextBox reportSpec = new TextBox();
  private TextBox reportData = new TextBox();
  private MenuItem moveParameterUp = new MenuItem(Messages.getUIInstance().jfreereportactionui__0000(), (Command)null);
  private MenuItem moveParameterDown = new MenuItem(Messages.getUIInstance().jfreereportactionui__0001(), (Command)null);
  public static interface ItemCommand {
    public void execute(String text);
  }  public static interface CommandHelper {
    public Command getCommand(MenuItem item);
  }
  ItemCommand addParameterCommand;
  CommandHelper addParameterCommandHelper;
  private MenuItem deleteParameter = new MenuItem(Messages.getUIInstance().jfreereportactionui_X(), (Command)null);
  private ScrollPanel parameterTableScroller = new ScrollPanel();
  private MenuItem moveSubreportUp = new MenuItem(Messages.getUIInstance().jfreereportactionui__0002(), (Command)null);
  private MenuItem moveSubreportDown = new MenuItem(Messages.getUIInstance().jfreereportactionui__0003(), (Command)null);
  ItemCommand addSubreportCommand;
  CommandHelper addSubreportCommandHelper;
  private MenuItem deleteSubreport = new MenuItem(Messages.getUIInstance().jfreereportactionui_X(), (Command)null);
  private ScrollPanel subreportTableScroller = new ScrollPanel();
  private TextBox reportFormat = new TextBox();
  private TextBox outputName = new TextBox();


  public void init() {
    Label obj89 = new Label(Messages.getUIInstance().jfreereportactionui_Name());
    root.setWidget(0,0,obj89);
    root.getFlexCellFormatter().setColSpan(0,0,2);
    root.setWidget(1,0,name);
    root.getFlexCellFormatter().setColSpan(1,0,2);
    Label obj90 = new Label(Messages.getUIInstance().jfreereportactionui_ReportSpecification());
    root.setWidget(2,0,obj90);
    root.setWidget(3,0,reportSpec);
    Label obj91 = new Label(Messages.getUIInstance().jfreereportactionui_ReportData());
    root.setWidget(2,1,obj91);
    root.setWidget(3,1,reportData);
    Label obj92 = new Label(Messages.getUIInstance().jfreereportactionui_ReportParameters());
    root.setWidget(4,0,obj92);
    root.getColumnFormatter().setWidth(0, "50%");
    MenuBar obj93 = new MenuBar();
    obj93.addItem(moveParameterUp);
    obj93.addItem(moveParameterDown);
    MenuItem obj94 = new MenuItem(Messages.getUIInstance().jfreereportactionui_Add(), (Command)null);
    MenuBar obj95 = new MenuBar(true);
    MenuItem obj96 = new MenuItem(Messages.getUIInstance().jfreereportactionui_Dummy(), (Command)null);
    obj95.addItem(obj96);
    obj96.setCommand(addParameterCommandHelper.getCommand(obj96));
    obj94.setSubMenu(obj95);
    obj93.addItem(obj94);
    obj93.addItem(deleteParameter);
    root.setWidget(5,0,obj93);
    root.getFlexCellFormatter().setHorizontalAlignment(5,0,HasHorizontalAlignment.ALIGN_RIGHT);
    parameterTableScroller.setWidth("100%");
    parameterTableScroller.setHeight("100px");
    parameterTableScroller.setAlwaysShowScrollBars(true);
    root.setWidget(6,0,parameterTableScroller);
    Label obj97 = new Label(Messages.getUIInstance().jfreereportactionui_SubreportDataQueries());
    root.setWidget(4,1,obj97);
    root.getColumnFormatter().setWidth(1, "50%");
    MenuBar obj98 = new MenuBar();
    obj98.addItem(moveSubreportUp);
    obj98.addItem(moveSubreportDown);
    MenuItem obj99 = new MenuItem(Messages.getUIInstance().jfreereportactionui_Add(), (Command)null);
    MenuBar obj100 = new MenuBar(true);
    MenuItem obj101 = new MenuItem(Messages.getUIInstance().jfreereportactionui_Dummy(), (Command)null);
    obj100.addItem(obj101);
    obj101.setCommand(addSubreportCommandHelper.getCommand(obj101));
    obj99.setSubMenu(obj100);
    obj98.addItem(obj99);
    obj98.addItem(deleteSubreport);
    root.setWidget(5,1,obj98);
    root.getFlexCellFormatter().setHorizontalAlignment(5,1,HasHorizontalAlignment.ALIGN_RIGHT);
    subreportTableScroller.setWidth("100%");
    subreportTableScroller.setHeight("100px");
    subreportTableScroller.setAlwaysShowScrollBars(true);
    root.setWidget(6,0,subreportTableScroller);
    Label obj102 = new Label(Messages.getUIInstance().jfreereportactionui_ReportFormat());
    root.setWidget(6,0,obj102);
    root.setWidget(7,0,reportFormat);
    Label obj103 = new Label(Messages.getUIInstance().jfreereportactionui_OutputReportName());
    root.setWidget(6,1,obj103);
    root.setWidget(7,1,outputName);
    root.setWidth("100%");

  }

  public FlexTable getRoot() {
    return root;
  }
  public TextBox getName() {
    return name;
  }
  public TextBox getReportSpec() {
    return reportSpec;
  }
  public TextBox getReportData() {
    return reportData;
  }
  public MenuItem getMoveParameterUp() {
    return moveParameterUp;
  }
  public MenuItem getMoveParameterDown() {
    return moveParameterDown;
  }
  public void setAddParameterCommand(ItemCommand itemCommand) {
    this.addParameterCommand = itemCommand;
    addParameterCommandHelper = new CommandHelper() {
      public Command getCommand(final MenuItem item) {
        Command cmd = new Command() {
          public void execute() {
            addParameterCommand.execute(item.getText());
          }
        };
        return cmd;
      }
    };
  }
  public MenuItem getDeleteParameter() {
    return deleteParameter;
  }
  public ScrollPanel getParameterTableScroller() {
    return parameterTableScroller;
  }
  public MenuItem getMoveSubreportUp() {
    return moveSubreportUp;
  }
  public MenuItem getMoveSubreportDown() {
    return moveSubreportDown;
  }
  public void setAddSubreportCommand(ItemCommand itemCommand) {
    this.addSubreportCommand = itemCommand;
    addSubreportCommandHelper = new CommandHelper() {
      public Command getCommand(final MenuItem item) {
        Command cmd = new Command() {
          public void execute() {
            addSubreportCommand.execute(item.getText());
          }
        };
        return cmd;
      }
    };
  }
  public MenuItem getDeleteSubreport() {
    return deleteSubreport;
  }
  public ScrollPanel getSubreportTableScroller() {
    return subreportTableScroller;
  }
  public TextBox getReportFormat() {
    return reportFormat;
  }
  public TextBox getOutputName() {
    return outputName;
  }

}
